package com.qt.collection.myset;

import com.qt.collection.Student2;

import java.util.Comparator;
import java.util.TreeSet;

public class TreeSetDemo02 {

    public static void main(String[] args) {

        TreeSet<Student2> ts = new TreeSet<>(( o1,  o2)-> {
                int sum1 = o1.getChinese() + o1.getMath() + o1.getEnglish();
                int sum2 = o2.getChinese() + o2.getMath() + o2.getEnglish();
                int res = sum2 - sum1;
                res = res == 0 ? o2.getChinese() - o1.getChinese() : res;
                res = res == 0 ? o2.getMath() - o1.getMath() : res;
                res = res == 0 ? o2.getEnglish() - o1.getEnglish() : res;
                res = res == 0 ? o2.compareTo(o1) : res;
                return res;
        });
        ts.add(new Student2("zhangsan", 23, 99, 88,67));
        ts.add(new Student2("lisi", 23, 97, 78,67));
        ts.add(new Student2("wagnwu", 23, 99, 48,67));
        ts.add(new Student2("zhaoliu", 23, 98, 68,67));

        for (Student2 t : ts) {
            System.out.println(t);
        }




    }
}
